<template>
	<view>
		<view class="userInfo">
			<image class="headImage" :src="userInfo.head"></image>
			<view class="info">
				<text>{{userInfo.nickname || ""}}</text>
				<text>{{userInfo.username || ""}}</text>
				<text>注册时间：{{userInfo.create_time || "未登录"}}</text>
			</view>
		</view>
		<view class="inviteInfo" v-if="parent != null">
			<text class="invite_title">我的推荐人</text>
			<view class="line"></view>
			<view class="invite">
				<image :src="parent.head"></image>
				<view class="invite_info">
					<view>
						<text>{{parent.nickname}}</text>
					</view>
					<text>邀请码：{{parent.code}}</text>
					<view class="phone">
						<text>绑定手机：{{parent.username}}</text>
						<text class="copyBtn" style="color: red;">复制</text>
					</view>
				</view>
			</view>
		</view>
		<view class="list">
            <view class="list-cell" @click="handleorder">
                  <view class="cell">
					  <text>我的订单</text>
					  <view>
						  <image src="/static/fanli/9.png"></image>
					  </view>
				  </view>
             </view>
			 <button open-type="contact">
				<view class="cell">
					<text>客服</text>
					<view>
						<image src="/static/fanli/9.png"></image>
					</view>
				</view>
			 </button>
			 <view class="list-cell" @click="handlehelp">
                  <view class="cell">
					  <text>帮助中心</text>
					  <view>
						  <image src="/static/fanli/9.png"></image>
					  </view>
				  </view>
             </view> 
			 <view class="list-cell" @click="handleLogout">
                  <view class="cell">
					  <text>退出登录</text>
					  <view>
						  <image src="/static/fanli/9.png"></image>
					  </view>
				  </view>
             </view>
        </view>
	</view>
</template>

<script>
	import {
		JSMRequest
	} from '@/module/api'
	import { getToken, saveToken} from '@/common/util'
	
	const _ = require("@/libs/underscore/underscore-min.js")._
	
	export default {
		data() {
			return {
				parent: null
			}
		},
		
		computed: {
			userInfo () {
				return this.$store.state.userInfo
			}
		},
		
		onLoad() {
			this.getPageData()
		},
		
		methods: {
			
			getPageData () {
				let _t = this
				
				JSMRequest({
					tag: "jsm-parentInfo"
				}).then(({data}) => {
					if(!_.isEmpty(data)) _t.parent = data
				})
			},
			
			handleorder () {
				uni.navigateTo({
					url:'/pageMe/me/order-list/order-list'
				})
			},
			
			handlehelp () {
				uni.navigateTo({
					url:'/pageMe/new/help/help'
				})
			},
			
			handleLogout () {
				saveToken({
					data: ""
				})
				
				this.$store.dispatch('updateUserInfo', null)
			}
		}
	}
</script>

<style lang="less" scoped>
.userInfo {
	flex-direction: row;
	align-items: center;
	display: flex;
	padding-left: 50px;
	padding-top: 30px;
	.headImage {
		width: 128px;
		height: 128px;
		border-radius: 64px;
		background-color: #f1f1f1;
	}
	.info {
		margin-left: 20px;
		flex-direction: column;
		display: flex;
		text{
			font-size: 26px;
			color: gray;
		}
	}
}

.inviteInfo {
	margin-left: 30px;
	margin-right: 30px;
	border-radius: 20px;
	margin-top: 40px;
	background-color: white;
	padding: 20px;
	box-shadow: 0 0 20px rgba(0,0,0,.15);
	
	.invite_title {
		font-size: 30px;
	}
	.line {
		background-color: #F5F9FF;
		width: 100%;
		height: 1px;
		margin-top: 10px;
	}
	.invite {
		display: flex;
		flex-direction: row;
		align-items: center;
		.phone {
			display: flex;
			flex-direction: row;
		}
		.invite_info {
			display: flex;
			flex-direction: column;
			margin-left: 10px;
		}
		text {
			font-size: 26px;
			color: gray;
		}
	}
	image {
		width: 74px;
		height: 74px;
		border-radius: 37px;
		background-color: red;
	}
	.copyBtn {
		font-size: 26px;
		color: red;
		margin-left: 20px;
	}
}

.list {
	margin-top: 30px;
	.cell {
		height: 80px;
		padding-left: 40px;
		padding-right: 40px;
		align-items: center;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		border-bottom: 1px solid #eee;
		background: #FFFFFF;
		
		text {
			font-size: 28px;
		}
		image {
			width: 22px;
			height: 22px;
		}
	}
}
</style>
